{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Note\n",
"* Instructions have been included for each segment. You do not have to follow them exactly, but they are included to help you think through the steps."
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"# Dependencies and Setup\n",
"import pandas as pd\n",
"\n",
"# File to Load (Remember to Change These)\n",
"file_to_load = \"Resources/data_csv.csv\"\n",
"\n",
"# Read Purchasing File and store into Pandas data frame\n",
"purchase_data = pd.read_csv(file_to_load)"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"scrolled": true
},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" Name | \n",
" Age | \n",
" AgeGroup | \n",
" Item ID | \n",
" Item Name | \n",
" Item Price | \n",
"
\n",
" \n",
" \n",
" \n",
" 0 | \n",
" Junayd Pemberton | \n",
" 42 | \n",
" Adult | \n",
" 108 | \n",
" button | \n",
" 8.51 | \n",
"
\n",
" \n",
" 1 | \n",
" Phebe Maguire | \n",
" 40 | \n",
" Adult | \n",
" 143 | \n",
" eraser | \n",
" 11.03 | \n",
"
\n",
" \n",
" 2 | \n",
" Sara Shaffer | \n",
" 40 | \n",
" Adult | \n",
" 92 | \n",
" knife | \n",
" 0.20 | \n",
"
\n",
" \n",
" 3 | \n",
" Cathy George | \n",
" 31 | \n",
" Adult | \n",
" 100 | \n",
" wallet | \n",
" 10.95 | \n",
"
\n",
" \n",
" 4 | \n",
" Haiden Schmidt | \n",
" 45 | \n",
" Adult | \n",
" 131 | \n",
" vase | \n",
" 4.85 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" Name Age AgeGroup Item ID Item Name Item Price\n",
"0 Junayd Pemberton 42 Adult 108 button 8.51\n",
"1 Phebe Maguire 40 Adult 143 eraser 11.03\n",
"2 Sara Shaffer 40 Adult 92 knife 0.20\n",
"3 Cathy George 31 Adult 100 wallet 10.95\n",
"4 Haiden Schmidt 45 Adult 131 vase 4.85"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"purchase_data.head()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Customer Count"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"* Display the total number of customers\n"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" Total Customers | \n",
"
\n",
" \n",
" \n",
" \n",
" 0 | \n",
" 576 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" Total Customers\n",
"0 576"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Calculate the number of customers\n",
"\n",
"\n",
"# create a dataframe\n",
"\n",
"\n",
"# show the dataframe\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Purchase Analysis (Total)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"* Run basic calculations to obtain number of unique items, average price, etc.\n",
"\n",
"\n",
"* Create a summary data frame to hold the results\n",
"\n",
"\n",
"* Optional: give the displayed data cleaner formatting\n",
"\n",
"\n",
"* Display the summary data frame\n"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" # of Unique Items | \n",
" Avg Item Price | \n",
" Number of Item Purchases | \n",
" Total of All Purchases | \n",
"
\n",
" \n",
" \n",
" \n",
" 0 | \n",
" 179 | \n",
" $5.54 | \n",
" 780 | \n",
" $4,317.30 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" # of Unique Items Avg Item Price Number of Item Purchases \\\n",
"0 179 $5.54 780 \n",
"\n",
" Total of All Purchases \n",
"0 $4,317.30 "
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# get the number of unique items\n",
"\n",
"\n",
"# get the average price per item\n",
"\n",
"\n",
"# get the number of purchases (count)\n",
"\n",
"\n",
"# get the total of all items purchased (sum)\n",
"\n",
"\n",
"# create the summary table\n",
"\n",
"\n",
"# round the data in the summary table so that decimal amounts have 2 decimal places\n",
"\n",
"\n",
"# format the Average Item Price to show the dollar sign and 2 decimal places\n",
"\n",
"\n",
"# format the Total of All Purchases to show the dollar sign and 2 decimal places\n",
"\n",
"# display the summary table\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Customer Demographics"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"* Percentage and Count of Child Customers\n",
"\n",
"* Percentage and Count of Teen Customers\n",
"\n",
"* Percentage and Count of Adult Customers\n",
"\n",
"* Percentage and Count of Senior Citizen Customers\n",
"\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" Total | \n",
" % of Customers | \n",
"
\n",
" \n",
" \n",
" \n",
" Adult | \n",
" 370 | \n",
" 64.24% | \n",
"
\n",
" \n",
" Senior Citizen | \n",
" 118 | \n",
" 20.49% | \n",
"
\n",
" \n",
" Teen | \n",
" 61 | \n",
" 10.59% | \n",
"
\n",
" \n",
" Child | \n",
" 27 | \n",
" 4.69% | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" Total % of Customers\n",
"Adult 370 64.24%\n",
"Senior Citizen 118 20.49%\n",
"Teen 61 10.59%\n",
"Child 27 4.69%"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# take the value counts of the Age groups ( think that there may be more than 1 purchase per customer ** drop the duplicates**)\n",
"\n",
"\n",
"\n",
"\n",
"# calculate the percentages of the Age groups\n",
"\n",
"\n",
"# create the customer demographics dataframe\n",
"\n",
"\n",
"# round the decimal values to show 2 decimal places\n",
"\n",
"\n",
"# display the DataFrame\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n",
"## Purchasing Analysis (Age Group)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"* Run basic calculations to obtain purchase count, avg. purchase price, avg. purchase total per person etc. by age group\n",
"\n",
"\n",
"\n",
"\n",
"* Create a summary data frame to hold the results\n",
"\n",
"\n",
"* Optional: give the displayed data cleaner formatting\n",
"\n",
"\n",
"* Display the summary data frame"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" Purchase Count | \n",
" Avg Purchase Price | \n",
" Total Purchase Amount | \n",
" Avg Total Purchase Per Customer | \n",
"
\n",
" \n",
" \n",
" \n",
" Adult | \n",
" 494 | \n",
" $5.57 | \n",
" $2,749.45 | \n",
" $7.43 | \n",
"
\n",
" \n",
" Child | \n",
" 32 | \n",
" $5.09 | \n",
" $162.89 | \n",
" $6.03 | \n",
"
\n",
" \n",
" Senior Citizen | \n",
" 167 | \n",
" $5.40 | \n",
" $901.40 | \n",
" $7.64 | \n",
"
\n",
" \n",
" Teen | \n",
" 87 | \n",
" $5.79 | \n",
" $503.56 | \n",
" $8.26 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" Purchase Count Avg Purchase Price Total Purchase Amount \\\n",
"Adult 494 $5.57 $2,749.45 \n",
"Child 32 $5.09 $162.89 \n",
"Senior Citizen 167 $5.40 $901.40 \n",
"Teen 87 $5.79 $503.56 \n",
"\n",
" Avg Total Purchase Per Customer \n",
"Adult $7.43 \n",
"Child $6.03 \n",
"Senior Citizen $7.64 \n",
"Teen $8.26 "
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# run basic calculations (USE GROUP BY!!!)\n",
"# calculate the total counts of purchases by each Age Group\n",
"\n",
"# calculate the average amount per purchase per Age Group\n",
"\n",
"# calculate the total amounts of purchases per Age Group\n",
"\n",
"\n",
"# Calculate the normalized purchasing (Average total per person in each age group) \n",
"# HINT: use the totals from the customer demographics data frame above\n",
"\n",
"\n",
"# create the data frame\n",
"\n",
"\n",
"# format the data frame dollar columns\n",
"\n",
"\n",
"# display the data frame\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Age Demographics"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"* Establish bins for ages\n",
"\n",
"\n",
"* Categorize the existing players using the age bins. Hint: use pd.cut()\n",
"\n",
"\n",
"* Calculate the numbers and percentages by age group\n",
"\n",
"\n",
"* Create a summary data frame to hold the results\n",
"\n",
"\n",
"* Optional: round the percentage column to two decimal points\n",
"\n",
"\n",
"* Display Age Demographics Table\n"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" Total Count | \n",
" Percentage of Customers | \n",
"
\n",
" \n",
" \n",
" \n",
" <13 | \n",
" 27 | \n",
" 4.69% | \n",
"
\n",
" \n",
" 13-20 | \n",
" 61 | \n",
" 10.59% | \n",
"
\n",
" \n",
" 21-30 | \n",
" 81 | \n",
" 14.06% | \n",
"
\n",
" \n",
" 31-40 | \n",
" 89 | \n",
" 15.45% | \n",
"
\n",
" \n",
" 41-50 | \n",
" 84 | \n",
" 14.58% | \n",
"
\n",
" \n",
" 50-65 | \n",
" 116 | \n",
" 20.14% | \n",
"
\n",
" \n",
" 65+ | \n",
" 118 | \n",
" 20.49% | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" Total Count Percentage of Customers\n",
"<13 27 4.69%\n",
"13-20 61 10.59%\n",
"21-30 81 14.06%\n",
"31-40 89 15.45%\n",
"41-50 84 14.58%\n",
"50-65 116 20.14%\n",
"65+ 118 20.49%"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# create the bins for the ages\n",
"\n",
"\n",
"# use the age demo data frame to cut the ages into their bins and make a new data frame column\n",
"\n",
"\n",
"# calculate the numbers and percentages by each age group\n",
"\n",
"# first, calculate the total count for each age group\n",
"\n",
"# calculate the percentages within each age group\n",
"\n",
"\n",
"\n",
"# build the dataframe\n",
"\n",
"\n",
"\n",
"# display the dataframe (sort the panda index)\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Purchasing Analysis (Age)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"* Bin the purchase_data data frame by age\n",
"\n",
"\n",
"* Run basic calculations to obtain purchase count, avg. purchase price, avg. purchase total per person etc. in the table below\n",
"\n",
"\n",
"* Create a summary data frame to hold the results\n",
"\n",
"\n",
"* Optional: give the displayed data cleaner formatting\n",
"\n",
"\n",
"* Display the summary data frame"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" Name | \n",
" Age | \n",
" AgeGroup | \n",
" Item ID | \n",
" Item Name | \n",
" Item Price | \n",
" Age Range | \n",
"
\n",
" \n",
" \n",
" \n",
" 0 | \n",
" Junayd Pemberton | \n",
" 42 | \n",
" Adult | \n",
" 108 | \n",
" button | \n",
" 8.51 | \n",
" 41-50 | \n",
"
\n",
" \n",
" 1 | \n",
" Phebe Maguire | \n",
" 40 | \n",
" Adult | \n",
" 143 | \n",
" eraser | \n",
" 11.03 | \n",
" 41-50 | \n",
"
\n",
" \n",
" 2 | \n",
" Sara Shaffer | \n",
" 40 | \n",
" Adult | \n",
" 92 | \n",
" knife | \n",
" 0.20 | \n",
" 41-50 | \n",
"
\n",
" \n",
" 3 | \n",
" Cathy George | \n",
" 31 | \n",
" Adult | \n",
" 100 | \n",
" wallet | \n",
" 10.95 | \n",
" 31-40 | \n",
"
\n",
" \n",
" 4 | \n",
" Haiden Schmidt | \n",
" 45 | \n",
" Adult | \n",
" 131 | \n",
" vase | \n",
" 4.85 | \n",
" 41-50 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" Name Age AgeGroup Item ID Item Name Item Price Age Range\n",
"0 Junayd Pemberton 42 Adult 108 button 8.51 41-50\n",
"1 Phebe Maguire 40 Adult 143 eraser 11.03 41-50\n",
"2 Sara Shaffer 40 Adult 92 knife 0.20 41-50\n",
"3 Cathy George 31 Adult 100 wallet 10.95 31-40\n",
"4 Haiden Schmidt 45 Adult 131 vase 4.85 41-50"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# bin the purchase_data data frame by age using the age bins\n"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" Purchase Count | \n",
" Avg Purchase Price | \n",
" Total Purchase Amount | \n",
" Avg Total Purchase Per Customer | \n",
"
\n",
" \n",
" \n",
" \n",
" <13 | \n",
" 32 | \n",
" $5.09 | \n",
" $162.89 | \n",
" $6.03 | \n",
"
\n",
" \n",
" 13-20 | \n",
" 87 | \n",
" $5.79 | \n",
" $503.56 | \n",
" $8.26 | \n",
"
\n",
" \n",
" 21-30 | \n",
" 111 | \n",
" $5.43 | \n",
" $602.96 | \n",
" $7.44 | \n",
"
\n",
" \n",
" 31-40 | \n",
" 113 | \n",
" $6.58 | \n",
" $743.13 | \n",
" $8.35 | \n",
"
\n",
" \n",
" 41-50 | \n",
" 110 | \n",
" $5.11 | \n",
" $561.55 | \n",
" $6.69 | \n",
"
\n",
" \n",
" 50-65 | \n",
" 160 | \n",
" $5.26 | \n",
" $841.81 | \n",
" $7.26 | \n",
"
\n",
" \n",
" 65+ | \n",
" 167 | \n",
" $5.40 | \n",
" $901.40 | \n",
" $7.64 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" Purchase Count Avg Purchase Price Total Purchase Amount \\\n",
"<13 32 $5.09 $162.89 \n",
"13-20 87 $5.79 $503.56 \n",
"21-30 111 $5.43 $602.96 \n",
"31-40 113 $6.58 $743.13 \n",
"41-50 110 $5.11 $561.55 \n",
"50-65 160 $5.26 $841.81 \n",
"65+ 167 $5.40 $901.40 \n",
"\n",
" Avg Total Purchase Per Customer \n",
"<13 $6.03 \n",
"13-20 $8.26 \n",
"21-30 $7.44 \n",
"31-40 $8.35 \n",
"41-50 $6.69 \n",
"50-65 $7.26 \n",
"65+ $7.64 "
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# run basic calculations (USE GROUP BY!!!)\n",
"# calculate the total counts of purchases by each Age Range\n",
"\n",
"# calculate the average amount per purchase per Age Range\n",
"\n",
"# calculate the total amounts of purchases per Age Range\n",
"\n",
"\n",
"# Calculate the normalized purchasing (Average total per person in each age group) \n",
"# HINT: use the total count from the age demographics data frame from a few cells ago\n",
"\n",
"\n",
"# create the data frame\n",
"\n",
"\n",
"# format the data frame dollar columns\n",
"\n",
"\n",
"# display the data frame\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Top Spending Customers"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"* Run basic calculations to obtain the results in the table below\n",
"\n",
"\n",
"* Create a summary data frame to hold the results\n",
"\n",
"\n",
"* Sort the total purchase value column in descending order\n",
"\n",
"\n",
"* Optional: give the displayed data cleaner formatting\n",
"\n",
"\n",
"* Display a preview of the summary data frame\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" Purchase Count | \n",
" Avg Purchase Price | \n",
" Total of all Purchases | \n",
"
\n",
" \n",
" Name | \n",
" | \n",
" | \n",
" | \n",
"
\n",
" \n",
" \n",
" \n",
" Diesel England | \n",
" 3 | \n",
" $12.75 | \n",
" $38.25 | \n",
"
\n",
" \n",
" Ruby-May Monaghan | \n",
" 4 | \n",
" $9.03 | \n",
" $36.10 | \n",
"
\n",
" \n",
" Naomi John | \n",
" 5 | \n",
" $6.86 | \n",
" $34.31 | \n",
"
\n",
" \n",
" Callan Amos | \n",
" 3 | \n",
" $10.57 | \n",
" $31.72 | \n",
"
\n",
" \n",
" Kameron Collins | \n",
" 3 | \n",
" $10.01 | \n",
" $30.02 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" Purchase Count Avg Purchase Price Total of all Purchases\n",
"Name \n",
"Diesel England 3 $12.75 $38.25\n",
"Ruby-May Monaghan 4 $9.03 $36.10\n",
"Naomi John 5 $6.86 $34.31\n",
"Callan Amos 3 $10.57 $31.72\n",
"Kameron Collins 3 $10.01 $30.02"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# identify the top spending customers (HINT: GROUP BY the name column)\n",
"# calculate the purchase count\n",
"\n",
"# calculate the average price per user's purchase\n",
"\n",
"# calculate the total of all of the user's purchases\n",
"\n",
"\n",
"# make a data frame\n",
"\n",
"\n",
"# display the data frame and sort the values based on the total of all of the customers' purchases\n",
"\n",
"\n",
"# format the data frame dollar columns\n",
"\n",
"\n",
"# display the data frame\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Most Popular Items"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"* Retrieve the Item ID, Item Name, and Item Price columns\n",
"\n",
"\n",
"* Group by Item ID and Item Name. Perform calculations to obtain purchase count, average item price, and total purchase value\n",
"\n",
"\n",
"* Create a summary data frame to hold the results\n",
"\n",
"\n",
"* Sort the purchase count column in descending order\n",
"\n",
"\n",
"* Optional: give the displayed data cleaner formatting\n",
"\n",
"\n",
"* Display a preview of the summary data frame\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" | \n",
" # of Purchases | \n",
" Item Price | \n",
" Total Purchase Value | \n",
"
\n",
" \n",
" Item ID | \n",
" Item Name | \n",
" | \n",
" | \n",
" | \n",
"
\n",
" \n",
" \n",
" \n",
" 92 | \n",
" knife | \n",
" 13 | \n",
" $7.84 | \n",
" $101.92 | \n",
"
\n",
" \n",
" 178 | \n",
" bowl | \n",
" 12 | \n",
" $4.98 | \n",
" $59.73 | \n",
"
\n",
" \n",
" 145 | \n",
" twezzers | \n",
" 9 | \n",
" $8.09 | \n",
" $72.80 | \n",
"
\n",
" \n",
" 132 | \n",
" cookie jar | \n",
" 9 | \n",
" $5.36 | \n",
" $48.28 | \n",
"
\n",
" \n",
" 108 | \n",
" button | \n",
" 9 | \n",
" $7.02 | \n",
" $63.17 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" # of Purchases Item Price Total Purchase Value\n",
"Item ID Item Name \n",
"92 knife 13 $7.84 $101.92\n",
"178 bowl 12 $4.98 $59.73\n",
"145 twezzers 9 $8.09 $72.80\n",
"132 cookie jar 9 $5.36 $48.28\n",
"108 button 9 $7.02 $63.17"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Retrieve the Item ID, Item Name, and Item Price columns\n",
"itemData = purchase_data.loc[:, [\"Item ID\", \"Item Name\", \"Item Price\"]]\n",
"\n",
"# Group by Item ID and Item Name. Perform calculations to obtain purchase count, average item price, and total purchase value\n",
"itemCounts = itemData.groupby([\"Item ID\", \"Item Name\"]).count()[\"Item Price\"].rename(\"# of Purchases\")\n",
"avgItemPrice = itemData.groupby([\"Item ID\", \"Item Name\"]).mean()[\"Item Price\"]\n",
"totalItemPurchase = itemData.groupby([\"Item ID\", \"Item Name\"]).sum()[\"Item Price\"].rename(\"Total Purchase Value\")\n",
"\n",
"\n",
"# create the data frame\n",
"itemDF = pd.DataFrame({\n",
" \"# of Purchases\": itemCounts,\n",
" \"Item Price\": avgItemPrice,\n",
" \"Total Purchase Value\": totalItemPurchase\n",
"})\n",
"\n",
"# sort the data frame by the number of purchases\n",
"mostPopularItemDF = itemDF.sort_values(\"# of Purchases\", ascending=False)\n",
"\n",
"# format the data frame dollar columns\n",
"mostPopularItemDF[\"Item Price\"] = mostPopularItemDF[\"Item Price\"].map(\"${:,.2f}\".format)\n",
"mostPopularItemDF[\"Total Purchase Value\"] = mostPopularItemDF[\"Total Purchase Value\"].map(\"${:,.2f}\".format)\n",
"\n",
"# show the data frame\n",
"mostPopularItemDF.head()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Most Profitable Items"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"* Sort the above table by total purchase value in descending order\n",
"\n",
"\n",
"* Optional: give the displayed data cleaner formatting\n",
"\n",
"\n",
"* Display a preview of the data frame\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {
"scrolled": true
},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" | \n",
" # of Purchases | \n",
" Item Price | \n",
" Total Purchase Value | \n",
"
\n",
" \n",
" Item ID | \n",
" Item Name | \n",
" | \n",
" | \n",
" | \n",
"
\n",
" \n",
" \n",
" \n",
" 92 | \n",
" knife | \n",
" 13 | \n",
" $7.84 | \n",
" $101.92 | \n",
"
\n",
" \n",
" 145 | \n",
" twezzers | \n",
" 9 | \n",
" $8.09 | \n",
" $72.80 | \n",
"
\n",
" \n",
" 108 | \n",
" button | \n",
" 9 | \n",
" $7.02 | \n",
" $63.17 | \n",
"
\n",
" \n",
" 7 | \n",
" door | \n",
" 7 | \n",
" $8.89 | \n",
" $62.21 | \n",
"
\n",
" \n",
" 178 | \n",
" bowl | \n",
" 12 | \n",
" $4.98 | \n",
" $59.73 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" # of Purchases Item Price Total Purchase Value\n",
"Item ID Item Name \n",
"92 knife 13 $7.84 $101.92\n",
"145 twezzers 9 $8.09 $72.80\n",
"108 button 9 $7.02 $63.17\n",
"7 door 7 $8.89 $62.21\n",
"178 bowl 12 $4.98 $59.73"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Sort the above table by total purchase value in descending order\n",
"mostProfitableItemDF = itemDF.sort_values(\"Total Purchase Value\", ascending=False)\n",
"\n",
"# format the data frame dollar columns\n",
"mostProfitableItemDF[\"Item Price\"] = mostProfitableItemDF[\"Item Price\"].map(\"${:,.2f}\".format)\n",
"mostProfitableItemDF[\"Total Purchase Value\"] = mostProfitableItemDF[\"Total Purchase Value\"].map(\"${:,.2f}\".format)\n",
"\n",
"mostProfitableItemDF.head()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"anaconda-cloud": {},
"kernel_info": {
"name": "python3"
},
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.8"
},
"latex_envs": {
"LaTeX_envs_menu_present": true,
"autoclose": false,
"autocomplete": true,
"bibliofile": "biblio.bib",
"cite_by": "apalike",
"current_citInitial": 1,
"eqLabelWithNumbers": true,
"eqNumInitial": 1,
"hotkeys": {
"equation": "Ctrl-E",
"itemize": "Ctrl-I"
},
"labels_anchors": false,
"latex_user_defs": false,
"report_style_numbering": false,
"user_envs_cfg": false
},
"nteract": {
"version": "0.2.0"
}
},
"nbformat": 4,
"nbformat_minor": 2
}